package com.lancoo.cvas.controller;


import cn.hutool.core.collection.CollUtil;
import cn.hutool.http.server.HttpServerResponse;
import com.lancoo.cvas.aspect.LogAnnotation;
import com.lancoo.cvas.entity.*;
import com.lancoo.cvas.exception.BizException;
import com.lancoo.cvas.pojo.dto.CourseProhibitDto;
import com.lancoo.cvas.pojo.dto.FixDto;
import com.lancoo.cvas.pojo.vo.*;
import com.lancoo.cvas.service.*;
import com.lancoo.cvas.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.redisson.executor.TasksService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@Api(tags = "排课规则设置")
@RestController
@RequestMapping("/api/v5.0.1/web/rule")
public class BasicRuleController {


    @Resource
    private BasicRuleService basicRuleService;
    @Resource
    private RoomService roomService;
    @Resource
    private RuleTeachingClassProhibitService ruleTeachingClassProhibitService;

    @Resource
    private CourseService courseService;
    @Resource
    private RuleCourseProhibitService ruleCourseProhibitService;
    @Resource
    private TaskInfoService taskInfoService;

    @GetMapping("/getClassInfo")
    @ApiOperation("跨校区设置列表")
    @LogAnnotation(operationType = "3", operationContent = "获取跨校区设置列表")
    public Result<CampusCrossGetResponse> getClassInfo(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId,
                                                       @ApiParam(value = "年级id ", required = false) @RequestParam(required = false) String gradeId,
                                                       @ApiParam(value = "校区id ", required = false) @RequestParam(required = false) String campusId,
                                                       @ApiParam(value = "专业名模糊查询", required = false) @RequestParam(required = false) String keyWord,
                                                       @ApiParam(value = "页码", required = true) @RequestParam Integer currentPage,
                                                       @ApiParam(value = "页容", required = true) @RequestParam Integer pageSize) {
        return Result.ofSuccess(basicRuleService.getClassInfo(taskId, gradeId, keyWord, campusId, currentPage, pageSize));
    }

    @GetMapping("/syncUpdatePeriodSchemes")
    @ApiOperation("同步更新课时方案")
    @LogAnnotation(operationType = "2", operationContent = "同步更新课时方案")
    public Result<Object> syncUpdatePeriodSchemes(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId,
                                                              @ApiParam(value = "学校Id", required = true) @RequestParam String schoolId,
                                                              @ApiParam(value = "学期", required = true) @RequestParam String term) {
        return basicRuleService.syncUpdatePeriodSchemes(taskId, schoolId, term);
    }

    @GetMapping("/getPeriodSchemes")
    @ApiOperation("获取课时方案")
    @LogAnnotation(operationType = "3", operationContent = "获取课时方案")
    public Result<List<PeriodSchemeGroupVo>> getPeriodSchemes(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId,
                                                              @ApiParam(value = "学校Id", required = true) @RequestParam String schoolId,
                                                              @ApiParam(value = "学期", required = true) @RequestParam String term) {
        return Result.ofSuccess(basicRuleService.getPeriodSchemes(taskId, schoolId, term));
    }

    @GetMapping("/getWeekDays")
    @ApiOperation("获取课时方案设置")
    @LogAnnotation(operationType = "3", operationContent = "获取每日课时方案")
    public Result<List<RuleWeekDay>> getWeekDays(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId,
                                                 @ApiParam(value = "学校Id", required = true) @RequestParam String schoolId,
                                                 @ApiParam(value = "学期", required = false) @RequestParam(required = false) String term) {
        if (StringUtils.isBlank(term)) {
            TaskInfo taskInfo = taskInfoService.getById(taskId);
            term = taskInfo.getTerm();
        }

        return Result.ofSuccess(basicRuleService.getWeekDays(taskId, schoolId, term));
    }


    @PostMapping("/updateWeekDays")
    @ApiOperation("设置课时方案")
    @LogAnnotation(operationType = "2", operationContent = "设置课时方案")
    public Result<Boolean> updateWeekDay(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId,
                                         @ApiParam(value = "专业id主键 ", required = true) @RequestBody List<RuleWeekDay> ruleWeekDays) {
        return Result.ofSuccess(basicRuleService.updateWeekDay(taskId, ruleWeekDays));
    }

    @PostMapping("/setCampus")
    @ApiOperation("批量设置校区")
    @LogAnnotation(operationType = "2", operationContent = "编辑专业对应校区")
    public Result<Boolean> setCampus(@ApiParam(value = "班级id ", required = true) @RequestBody List<Long> classIds,
                                     @ApiParam(value = "校区id", required = true) @RequestParam String campusId,
                                     @ApiParam(value = "校区名字", required = true) @RequestParam String campusName) {
        return Result.ofSuccess(basicRuleService.setCampus(classIds, campusId, campusName));
    }

    @GetMapping("/getMaxPeriodScheme")
    @ApiOperation("获取最大课时方案")
    @LogAnnotation(operationType = "3", operationContent = "获取最大课时方案")
    public Result<MaxPeriodScheme> getMaxPeriodScheme(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId,
                                                      @ApiParam(value = "学校Id", required = true) @RequestParam String schoolId,
                                                      @ApiParam(value = "学期", required = true) @RequestParam(required = false) String term) {

        if (StringUtils.isBlank(term)) {
            TaskInfo taskInfo = taskInfoService.getById(taskId);
            term = taskInfo.getTerm();
        }

        return Result.ofSuccess(basicRuleService.getMaxPeriodScheme(taskId, schoolId, term));
    }

//    @PostMapping("/set")
//    @ApiOperation("设置基础规则")
//    @LogAnnotation(operationType = "2", operationContent = "设置基础规则")
//    public Result setBasicRule(@RequestBody List<BasicRule> basicRule, @RequestHeader Integer taskId) {
//        SetBasciRuleRequest setBasciRuleRequest = SetBasciRuleRequest.builder().rules(basicRule).taskId(taskId).build();
//        basicRuleService.setBasicRule(setBasciRuleRequest);
//        return Result.ofSuccess();
//    }

    @GetMapping("/getCurrentSet")
    @ApiOperation("获取当前的设置")
    @LogAnnotation(operationType = "3", operationContent = "获取当前的设置")
    public Result<List<RuleUsable>> getBasicRule(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId,
                                                 @ApiParam(value = "学校Id", required = true) @RequestParam String schoolId,
                                                 @ApiParam(value = "学期", required = true) @RequestParam String term) {
        return Result.ofSuccess(basicRuleService.getCurrent(taskId, schoolId, term));
    }

    @GetMapping("/getTimeProhibit")
    @ApiOperation("获取日期禁排")
    @LogAnnotation(operationType = "3", operationContent = "获取日期禁排")
    public Result<List<RuleTimeProhibit>> getTimeProhibit(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId,
                                                          @ApiParam(value = "学校Id", required = true) @RequestParam String schoolId,
                                                          @ApiParam(value = "学期", required = true) @RequestParam String term) {
        return Result.ofSuccess(basicRuleService.getTimeProhibit(taskId, schoolId, term));
    }

    @PostMapping("/setTimeProhibit")
    @ApiOperation("设置日期禁排")
    @LogAnnotation(operationType = "2", operationContent = "设置日期禁排")
    public Result<Integer> setTimeProhibit(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId,
                                           @ApiParam(value = "日期禁排实体类 ", required = true) @RequestBody RuleTimeProhibit ruleTimeProhibit) {
        return Result.ofSuccess(basicRuleService.setTimeProhibit(taskId, ruleTimeProhibit));
    }

    @PostMapping("/clearTimeProhibit")
    @ApiOperation("清空日期禁排")
    @LogAnnotation(operationType = "4", operationContent = "清空日期禁排")
    public Result<Boolean> clearTimeProhibit(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId) {
        return Result.ofSuccess(basicRuleService.clearTimeProhibit(taskId));
    }


    @ApiOperation("批量导入禁排规则")
    @PostMapping("/bulk/prohibit")
    @LogAnnotation(operationType = "13", operationContent = "批量导入禁排规则")
    public Result<String> excelToTeachingClass(HttpServletResponse response,
                                               @ApiParam(value = "禁排参数", required = true) ImportProhibit importProhibit,
                                               @ApiParam("file") @RequestPart("file") MultipartFile file) {
        //fileName 文件名
        String fileName = file.getOriginalFilename();
        assert fileName != null;
        if (!fileName.endsWith(".xls") && !fileName.endsWith(".xlsx")) {
            throw new BizException(5, "文件格式不正确");
        }
        return basicRuleService.excelToProhibit(response, importProhibit, file);
    }

    @GetMapping("/getRuleTeachingClass")
    @ApiOperation("获取禁排教学班")
    @LogAnnotation(operationType = "3", operationContent = "获取禁排教学班")
    public Result<List<RuleTeachingClassVo>> getRuleTeachingClass(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId,
                                                                  @ApiParam(value = "教室Id", required = false) @RequestParam(required = false) Long roomId,
                                                                  //根据教师筛选教学班  无关多教师
                                                                  @ApiParam(value = "教师", required = false) @RequestParam(required = false) Long teacherId,
                                                                  @ApiParam(value = "行政班id", required = false) @RequestParam(required = false) Long classId,
                                                                  @ApiParam(value = "教学班id", required = false) @RequestParam(required = false) Long teachingClassId
    ) {
        return Result.ofSuccess(basicRuleService.getRuleTeachingClass(taskId, roomId, teacherId, classId, teachingClassId));
    }


    @GetMapping("/getRoomProhibit")
    @ApiOperation("获取教室禁排")
    @LogAnnotation(operationType = "3", operationContent = "获取教室禁排")
    public Result<List<RuleRoomProhibit>> getRoomProhibit(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId,
                                                          @ApiParam(value = "学校Id", required = true) @RequestParam String schoolId,
                                                          @ApiParam(value = "学期", required = true) @RequestParam String term,
                                                          @ApiParam(value = "教室id", required = true) @RequestParam Long roomId) {
        return Result.ofSuccess(basicRuleService.getRoomProhibit(taskId, schoolId, term, roomId));
    }


    @PostMapping("/setRoomProhibit")
    @ApiOperation("设置教室禁排")
    @LogAnnotation(operationType = "2", operationContent = "设置教室禁排")
    public Result<Boolean> setRoomProhibit(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId,
                                           @ApiParam(value = "教室禁排实体类 ", required = true) @RequestBody RuleRoomProhibit ruleRoomProhibit) {
        return Result.ofSuccess(basicRuleService.setRoomProhibit(taskId, ruleRoomProhibit));
    }


    @Deprecated
    @GetMapping("/getTeachingClassFix")
    @ApiOperation("获取教学班固排课时")
    @LogAnnotation(operationType = "3", operationContent = "获取教学班固排课时")
    public Result<List<RuleTeachingClassProhibit>> getTeachingClassFix(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId,
                                                                       @ApiParam(value = "学校id", required = true) @RequestParam String schoolId,
                                                                       @ApiParam(value = "教学班id ", required = true) @RequestParam Long teachingClassId,
                                                                       @ApiParam(value = "授课方式", required = true) @RequestParam Integer hourType) {
        return Result.ofSuccess(ruleTeachingClassProhibitService.getTeachingClassTypeFix(taskId, teachingClassId, hourType));
    }


    @GetMapping("/checkProhibit")
    @ApiOperation("固排时获取教学班禁排数据")
    @LogAnnotation(operationType = "3", operationContent = "固排时获取教学班禁排数据")
    public Result<ProhibitCheckVo> checkProhibit(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId,
                                                 @ApiParam(value = "学校Id", required = true) @RequestParam String schoolId,
                                                 @ApiParam(value = "教室id", required = false) @RequestParam(required = false) Long roomId,
                                                 @ApiParam(value = "课程id", required = false) @RequestParam(required = false) Long courseId,
                                                 @ApiParam(value = "行政班id", required = false) @RequestParam(required = false) String classId,
                                                 @ApiParam(value = "教学班id", required = false) @RequestParam(required = false) Long teachingClassId,
                                                 @ApiParam(value = "教师id", required = false) @RequestParam(required = false) String teacherIds) {
        return Result.ofSuccess(basicRuleService.checkProhibit(taskId, schoolId, roomId, courseId, classId, teachingClassId, teacherIds));
    }


    @GetMapping("/checkTaskInfoName")
    @ApiOperation("固排时获取教学班禁排数据")
    @LogAnnotation(operationType = "3", operationContent = "检查任务名称")
    public Result<Boolean> checkTaskInfoName(@ApiParam(value = "教师id", required = false) @RequestParam String taskInfoName) {
        return Result.ofSuccess(basicRuleService.checkTaskInfoName(taskInfoName));
    }

    @GetMapping("/getFixConflict")
    @ApiOperation("检测固排冲突 是否与禁排冲突 是否超过固排课时")
    @LogAnnotation(operationType = "3", operationContent = "获取固排冲突 是否与禁排冲突 是否超过固排课时")
    public Result<FixVo> getFixConflict(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId,
                                        @ApiParam(value = "固排实体类 ", required = true) @RequestBody List<FixDto> fixDto) {
        return Result.ofSuccess(basicRuleService.getFixConflict(taskId, fixDto));
    }

//    @GetMapping("/getCourseFix")
//    @ApiOperation("获取固排课时")
//    public Result<Integer> getCourseFix(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId,
//                                        @ApiParam(value = "班级id ", required = true) @RequestParam(required = false) String classId,
//                                        @ApiParam(value = "教室id ", required = true) @RequestParam(required = false) Integer roomId,
//                                        @ApiParam(value = "学校id", required = true) @RequestParam String schoolId,
//                                        @ApiParam(value = "模糊查询关键字", required = true) @RequestParam String keyword,
//                                        @ApiParam(value = "学期", required = true) @RequestParam String term) {
//        return Result.ofSuccess(roomService.setRoom(taskId, classId, roomId, schoolId));
//    }

    @PostMapping("/setFix")
    @ApiOperation("设置固排")
    @LogAnnotation(operationType = "2", operationContent = "设置固排")
    public Result<FixVo> setFix(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId,
                                @ApiParam(value = "学校id", required = true) @RequestParam String schoolId,
                                @ApiParam(value = "学期", required = true) @RequestParam String term,
                                @ApiParam(value = "固排实体类 ", required = true) @RequestBody List<FixDto> fixDto) {
        return Result.ofSuccess(basicRuleService.setFix(taskId, schoolId, term, fixDto));
    }

    @PostMapping("/removeFix")
    @ApiOperation("取消固排")
    @LogAnnotation(operationType = "2", operationContent = "设置固排")
    public Result<Boolean> removeFix(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId,
                                     @ApiParam(value = "固排实体类 ", required = true) @RequestBody List<RuleTeachingClassProhibit> ruleList) {
        if (CollUtil.isEmpty(ruleList)) {
            return Result.ofFail("规则为空");
        }
        String schoolId = ruleList.get(0).getSchoolId();
        String term = ruleList.get(0).getTerm();
        return Result.ofSuccess(basicRuleService.removeFix(taskId, schoolId, term, ruleList));
    }


    @GetMapping("/getTeacherSetting")
    @ApiOperation("获取教师统一设置")
    @LogAnnotation(operationType = "3", operationContent = "获取教师统一设置")
    public Result<RuleTeacherSetting> getTeacherSetting(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId) {
        return Result.ofSuccess(basicRuleService.getTeacherSetting(taskId));
    }

    @PostMapping("/setTeacherSetting")
    @ApiOperation("设置教师统一设置")
    @LogAnnotation(operationType = "2", operationContent = "设置教师统一设置")
    public Result<Boolean> setTeacherSetting(@ApiParam(value = "教师统一设置实体类", required = true) @RequestBody RuleTeacherSetting ruleTeacherSetting) {
        return Result.ofSuccess(basicRuleService.setTeacherSetting(ruleTeacherSetting));
    }

    @Deprecated
    @PostMapping("/enableTeacherSetting")
    @ApiOperation("教师统一设置开关")
    @LogAnnotation(operationType = "2", operationContent = "设置教师统一设置开关")
    public Result<Boolean> enableTeacherSetting(@ApiParam(value = "教师统一设置实体类", required = true) @RequestBody RuleTeacherSetting ruleTeacherSetting) {
        return Result.ofSuccess(basicRuleService.setTeacherSetting(ruleTeacherSetting));
    }

    @GetMapping("/getTeacherProhibit")
    @ApiOperation("获取教师禁排")
    @LogAnnotation(operationType = "3", operationContent = "获取教师禁排")
    public Result<List<RuleTeacherTime>> getTeacherProhibit(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId,
                                                            @ApiParam(value = "学校id", required = true) @RequestParam String schoolId,
                                                            @ApiParam(value = "学期", required = true) @RequestParam String term,
                                                            @ApiParam(value = "教师id", required = true) @RequestParam Integer teacherId) {
        return Result.ofSuccess(basicRuleService.getTeacherProhibit(taskId, schoolId, term, teacherId));
    }

    @PostMapping("/setTeacherProhibit")
    @ApiOperation("设置教师禁排")
    @LogAnnotation(operationType = "2", operationContent = "设置教师禁排")
    public Result<Boolean> setTeacherTimeProhibit(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId,
                                                  @ApiParam(value = "教师时间禁排实体类", required = true) @RequestBody RuleTeacherTime ruleTeacherTime) {
        if (ruleTeacherTime.getTeacherId() == null) {
            Result.ofFail("教师id不能为空");
        }
        return Result.ofSuccess(basicRuleService.setTeacherTimeProhibit(taskId, ruleTeacherTime));
    }

    @GetMapping("/getClassProhibit")
    @ApiOperation("获取行政班禁排")
    @LogAnnotation(operationType = "3", operationContent = "获取行政班禁排")
    public Result<List<RuleClassProhibit>> getClassProhibit(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId,
                                                            @ApiParam(value = "学校id", required = true) @RequestParam String schoolId,
                                                            @ApiParam(value = "行政班id", required = true) @RequestParam Long classId) {
        return Result.ofSuccess(basicRuleService.getClassProhibit(taskId, schoolId, classId));
    }

    @PostMapping("/setClassProhibit")
    @ApiOperation("设置行政班禁排")
    @LogAnnotation(operationType = "2", operationContent = "设置行政班禁排")
    public Result<Boolean> setClassProhibit(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId,
                                            @ApiParam(value = "行政班禁排实体类", required = true) @RequestBody RuleClassProhibit ruleClassProhibit) {
        if (ruleClassProhibit.getClassId() == null) {
            Result.ofFail("行政班id不能为空");
        }
        return Result.ofSuccess(basicRuleService.setClassProhibit(taskId, ruleClassProhibit));
    }

    @GetMapping("/getTeachingClassProhibit")
    @ApiOperation("获取教学班禁排")
    @LogAnnotation(operationType = "3", operationContent = "获取教学班禁排")
    public Result<List<RuleTeachingClassProhibit>> getTeachingClassProhibit(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId,
                                                                            @ApiParam(value = "学校id", required = true) @RequestParam String schoolId,
                                                                            @ApiParam(value = "教学班id", required = true) @RequestParam Long teachingClassId) {
        return Result.ofSuccess(basicRuleService.getTeachingClassProhibit(taskId, schoolId, teachingClassId));
    }


    @PostMapping("/setTeachingClassProhibit")
    @ApiOperation("设置教学班禁排")
    @LogAnnotation(operationType = "2", operationContent = "设置教学班禁排")
    public Result<Boolean> setTeachingClassProhibit(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId,
                                                    @ApiParam(value = "教学班禁排实体类", required = true) @RequestBody RuleTeachingClassProhibit ruleTeachingClassProhibit) {
        if (ruleTeachingClassProhibit.getTeachingClassId() == null) {
            Result.ofFail("行政班id不能为空");
        }
        return Result.ofSuccess(basicRuleService.setTeachingClassProhibit(taskId, ruleTeachingClassProhibit));
    }

    @GetMapping("/getAllCourseProhibit")
    @ApiOperation("获取所有课程禁排规则")
    @LogAnnotation(operationType = "3", operationContent = "获取所有课程禁排规则")
    public Result<List<RuleCourse>> getAllCourseProhibit(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId,
                                                         @ApiParam(value = "搜素", required = false) @RequestParam(required = false) String keyword) {
        return Result.ofSuccess(ruleCourseProhibitService.getAllCourseProhibit(taskId, keyword));
    }

    @GetMapping("/getCourseProhibitDetail")
    @ApiOperation("获取课程规则详情")
    @LogAnnotation(operationType = "3", operationContent = "获取课程规则详情")
    public Result<List<RuleCourseProhibit>> getCourseProhibitDetail(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId,
                                                         @ApiParam(value = "年级id", required = true) @RequestParam String gradeId,
                                                         @ApiParam(value = "课程id", required = true) @RequestParam Long courseId) {
        return Result.ofSuccess(ruleCourseProhibitService.getCourseProhibitDetail(taskId, gradeId,courseId));
    }

    @PostMapping("/setCourseProhibit")
    @ApiOperation("设置课程禁排")
    @LogAnnotation(operationType = "2", operationContent = "设置课程禁排")
    public Result<Boolean> setCourseProhibit(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId,
                                             @ApiParam(value = "学校Id", required = true) @RequestParam String schoolId,
                                             @ApiParam(value = "学期", required = true) @RequestParam String term,
                                             @ApiParam(value = "年级id", required = true) @RequestParam String gradeId,
                                             @ApiParam(value = "课程id", required = true) @RequestParam Long courseId,
                                             @ApiParam(value = "课程禁排实体类", required = true) @RequestBody CourseProhibitDto courseProhibitList) {
        return Result.ofSuccess(ruleCourseProhibitService.setCourseProhibitV2(taskId, gradeId,courseId, courseProhibitList, schoolId, term));
    }

    @GetMapping("/getAllProhibitCourses")
    @ApiOperation("获取所有禁排课程下拉框")
    @LogAnnotation(operationType = "3", operationContent = "获取所有禁排课程下拉框")
    public Result<List<GradeCourseVo>> getAllProhibitCourses(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId) {
        return Result.ofSuccess(ruleCourseProhibitService.getAllProhibitCoursesV2(taskId,true));
    }





//    @GetMapping("/getAllProhibitCourses")
//    @ApiOperation("获取所有禁排课程下拉框")
//    public Result<List<CourseAndMajor>> getAllProhibitCourses(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId) {
//        return Result.ofSuccess(ruleCourseProhibitService.getAllProhibitCourses(taskId));
//    }

//    @PostMapping("/setCourseProhibit")
//    @ApiOperation("设置课程禁排")
//    @LogAnnotation(operationType = "2", operationContent = "设置课程禁排")
//    public Result<Boolean> setCourseProhibit(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId,
//                                             @ApiParam(value = "课程禁排实体类", required = true) @RequestBody CourseProhibitDto courseProhibitList) {
//        return Result.ofSuccess(ruleCourseProhibitService.setCourseProhibit(taskId, courseProhibitList));
//    }

    @PostMapping("/delCourseProhibit")
    @ApiOperation("删除课程禁排")
    @LogAnnotation(operationType = "4", operationContent = "删除课程禁排")
    public Result<Boolean> delCourseProhibit(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId,
                                             @ApiParam(value = "删除实体", required = true) @RequestBody BatchCourseRule rule
    ) {
        if (rule == null || rule.getRuleId() == null || rule.getCourseId() == null) {
            return Result.ofFail("参数不合法");
        }
        return Result.ofSuccess(ruleCourseProhibitService.delCourseProhibit(taskId, rule.getRuleId(), rule.getCourseId(),rule.getGradeId(), rule.getSchoolId(), rule.getTerm()));
    }

    @PostMapping("/delCourseProhibitBatch")
    @ApiOperation("批量删除课程禁排")
    @LogAnnotation(operationType = "4", operationContent = "批量删除课程禁排")
    public Result<Boolean> delCourseProhibitBatch(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId,
                                                  @ApiParam(value = "删除实体", required = true) @RequestBody List<BatchCourseRule> rules
    ) {
        if (CollUtil.isEmpty(rules)) {
            return Result.ofFail("id为空");
        }
        String schoolId = rules.get(0).getSchoolId();
        String term = rules.get(0).getTerm();
        return Result.ofSuccess(ruleCourseProhibitService.delCoursdelCourseProhibitBatcheProhibit(taskId, rules, schoolId, term));
    }

    @PostMapping("/bulk/courseProhibit")
    @ApiOperation("导入课程规则")
    @LogAnnotation(operationType = "13", operationContent = "导入课程规则")
    public Result<Object> importCourseProhibit(HttpServletResponse response,
//                                               @ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId,
                                               @ApiParam(value = "禁排参数", required = true) ImportProhibit importProhibit,
                                               @ApiParam("file") @RequestPart("file") MultipartFile file
    ) throws Exception {
        //fileName 文件名
        String fileName = file.getOriginalFilename();
        assert fileName != null;
        if (!fileName.endsWith(".xls") && !fileName.endsWith(".xlsx")) {
            throw new BizException(5, "文件格式不正确");
        }
        return ruleCourseProhibitService.importCourseProhibitV2(response, importProhibit.getTaskId(), importProhibit, file);
    }


//    @GetMapping("/getCourseProhibit")
//    @ApiOperation("获取课程的禁排信息")
//    public Result<RuleCourseProhibitVo> getCourseProhibit(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId,
//                                                          @ApiParam(value = "课程id", required = true) @RequestParam Long courseId
//    ) {
//        return Result.ofSuccess(ruleCourseProhibitService.getCourseProhibit(taskId, courseId));
//    }


    //    @GetMapping("/getRuleProhibit")
//    @ApiOperation("获取规则详情")
//    public Result<RuleCourseProhibitVo> getRuleProhibit(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId,
//                                                          @ApiParam(value = "课程禁排id", required = true) @RequestParam Long ruleId
//    ) {
//        return Result.ofSuccess(ruleCourseProhibitService.getRuleProhibit(taskId, ruleId));
//    }


    @GetMapping("/getBaseRule")
    @ApiOperation("获取基础规则")
    @LogAnnotation(operationType = "3", operationContent = "获取基础规则")
    public Result<List<RuleUsable>> getBaseRule(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId) {
        return Result.ofSuccess(basicRuleService.getBaseRule(taskId));
    }

    @PostMapping("/setBaseRule")
    @ApiOperation("设置基础规则")
    @LogAnnotation(operationType = "2", operationContent = "设置基础规则")
    public Result<Boolean> setBaseRule(@ApiParam(value = "任务流程id", required = true) @RequestHeader Integer taskId,
                                       @ApiParam(value = "基础规则实体类", required = true) @RequestBody List<RuleUsable> ruleUsableList) {
        return Result.ofSuccess(basicRuleService.setBaseRule(taskId, ruleUsableList));
    }


}
